package com.example.mykotlin.base.result

import io.swagger.v3.oas.annotations.media.Schema
import org.slf4j.Logger
import org.slf4j.LoggerFactory

data class R<T>(
    @Schema(title = "业务标识 true:成功 false:失败")
    var flag: Boolean? = true,
    @Schema(title = "业务状态码 000000:成功")
    var code: String? = "",
    @Schema(title = "业务信息")
    var msg: String? = "",
    var data: T? = null
) {
    companion object {
        val LOG: Logger = LoggerFactory.getLogger(Companion::class.java)

        fun <T : Any> ok(
            data: T? = null,
            code: String = ResultCode.SUCCESS.code,
            msg: String = ResultCode.SUCCESS.msg
        ) =
            R(true, code, msg, data)

        fun <T : Any> fail(data: T? = null, code: String = ResultCode.FAIL.code, msg: String = ResultCode.FAIL.msg) =
            R(false, code, msg, data)


    }

}
